import Vue from 'vue'
import Router from 'vue-router'

// in development-env not use lazy-loading, because lazy-loading too many pages will cause webpack hot update too slow. so only in production use lazy-loading;
// detail: https://panjiachen.github.io/vue-element-admin-site/#/lazy-loading

Vue.use(Router)

/* Layout */
import Layout from '../views/layout/Layout'

/**
 * hidden: true                   if `hidden:true` will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu, whatever its child routes length
 *                                if not set alwaysShow, only more than one route under the children
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noredirect           if `redirect:noredirect` will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    title: 'title'               the name show in submenu and breadcrumb (recommend set)
    icon: 'svg-name'             the icon show in the sidebar,
  }
 **/
export const constantRouterMap = [
  {path: '/login', component: () => import('@/views/login/index'), hidden: true},
  {path: '/404', component: () => import('@/views/404'), hidden: true},

  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    name: '',
    hidden: true,
    children: [{
      path: 'dashboard',
      component: () => import('@/views/dashboard/index')
    }]
  },

  {
    path: '/user',
    component: Layout,
    redirect: '/user/index',
    name: '用户管理',
    meta: {title: '用户管理', icon: 'user'},
    children: [
      {
        path: 'index',
        name: '用户管理',
        component: () => import('@/views/user/index'),
        meta: {title: '用户管理', icon: 'user'}
      }
    ]
  },

  {
    path: '/subject',
    component: Layout,
    redirect: '/subject/index',
    name: '类目管理',
    meta: {title: '类目管理', icon: 'subject'},
    children: [
      {
        path: 'index',
        name: '类目管理',
        component: () => import('@/views/subject/index'),
        meta: {title: '类目管理', icon: 'subject'}
      }
    ]
  },

  {
    path: '/course',
    component: Layout,
    redirect: '/course/index',
    name: '课程管理',
    meta: {title: '课程管理', icon: 'course'},
    children: [
      {
        path: 'index',
        name: '课程管理',
        component: () => import('@/views/course/index'),
        meta: {title: '课程管理', icon: 'course'}
      },
      {
        path: 'courseInfo/:id',
        name: '课程信息',
        component: () => import('@/views/course/courseInfo'),
        meta: { title: '课程信息' },
        hidden: true
      },
      {
        path: 'chapterInfo/:id',
        name: '章节信息',
        component: () => import('@/views/course/chapterInfo'),
        meta: { title: '章节信息' },
        hidden: true
      }
    ]
  },

  {
    path: '/order',
    component: Layout,
    redirect: '/order/index',
    name: '订单管理',
    meta: {title: '订单管理', icon: 'order'},
    children: [
      {
        path: 'index',
        name: '订单管理',
        component: () => import('@/views/order/index'),
        meta: {title: '订单管理', icon: 'order'}
      }
    ]
  },

  {
    path: '/listen',
    component: Layout,
    redirect: '/listen/index',
    name: '听力管理',
    meta: {title: '听力管理', icon: 'listen'},
    children: [
      {
        path: 'index',
        name: '听力管理',
        component: () => import('@/views/listen/index'),
        meta: {title: '听力管理', icon: 'listen'}
      },
      {
        path: 'details',
        name: '听力详情',
        component: () => import('@/views/listen/details'),
        meta: { title: '听力详情' },
        hidden: true
      }
    ]
  },

  {
    path: '/completion',
    component: Layout,
    redirect: '/completion/index',
    name: '完形填空',
    meta: {title: '完形填空', icon: 'completion'},
    children: [
      {
        path: 'index',
        name: '完形填空',
        component: () => import('@/views/completion/index'),
        meta: {title: '完形填空', icon: 'completion'}
      }
    ]
  },

  {
    path: '/matching',
    component: Layout,
    redirect: '/matching/index',
    name: '段落匹配',
    meta: {title: '段落匹配', icon: 'matching'},
    children: [
      {
        path: 'list',
        name: '段落匹配',
        component: () => import('@/views/matching/index'),
        meta: {title: '段落匹配', icon: 'matching'}
      }
    ]
  },

  {
    path: '/read',
    component: Layout,
    redirect: '/read/index',
    name: '阅读管理',
    meta: {title: '阅读管理', icon: 'read'},
    children: [
      {
        path: 'index',
        name: '阅读管理',
        component: () => import('@/views/read/index'),
        meta: {title: '阅读管理', icon: 'read'}
      }
    ]
  },

  {
    path: '/write',
    component: Layout,
    redirect: '/write/index',
    name: '写作管理',
    meta: {title: '写作管理', icon: 'write'},
    children: [
      {
        path: 'index',
        name: '写作管理',
        component: () => import('@/views/write/index'),
        meta: {title: '写作管理', icon: 'write'}
      }
    ]
  },

  {
    path: '/translation',
    component: Layout,
    redirect: '/translation/index',
    name: '翻译管理',
    meta: {title: '翻译管理', icon: 'translation'},
    children: [
      {
        path: 'index',
        name: '翻译管理',
        component: () => import('@/views/translation/index'),
        meta: {title: '翻译管理', icon: 'translation'}
      }
    ]
  },

  {path: '*', redirect: '/404', hidden: true}
]

export default new Router({
  // mode: 'history', //后端支持可开
  scrollBehavior: () => ({y: 0}),
  routes: constantRouterMap
})
